--
-- Author: ping.wang
-- Date: 2019-03-12 17:13:04
--
-- PvpDuelFightEndFailedView
--
local IconRender = require("app.widget.renders.IconRender")
local fileName = string.getModeName(...)
local ClassRef = class(fileName, app.mvc.ViewBase)

ClassRef.VIEW_ROOT_RES = Res.PvpDuelFightEndFailedScene

function ClassRef:init()
    self._ui.Button_close:addClickEventListener(function()
        self:closeView()
    end)

    self._ui.tips_1:setString(L("duelGametips23"))
    self._ui.tips_2:setString(L("duelGametips25"))
    self._ui.tlt:setString(L("duelGametips21"))
    local rewards = self._data.loot
    for i,reward in ipairs(rewards) do
        local itemData = UD:parseLootToBagItem( reward )
        local render = IconRender.createWithData( itemData, self._ui["icon_" .. i] )
        render:setTipEnable( true )
        render:setTipUnShowOrigin( true )
    end

    self:_autoAdjustRewardPanel(#rewards)

end

-- 自动调整奖励panel中奖励posX
function ClassRef:_autoAdjustRewardPanel(visibleNum)
    for i = 1, 3 do
        self._ui["icon_" .. i]:setVisible(i <= visibleNum)
    end

    if 1 == visibleNum then
        self._ui.icon_1:setPositionX(self._ui.icon_2:getPositionX())
    elseif 2 == visibleNum then
        local width = self._ui.Panel:getContentSize2()
        self._ui.icon_1:setPositionX( width*0.35 - 38) -- 常量系数是UI中的posX比例
        self._ui.icon_2:setPositionX( width*0.65 - 38)
    end
end

return ClassRef
